package egg

import (
	"math/rand"
)

// 蛋存在的目的是为了以最小的字节数串行化存储Frog,它是Frog的生成算法描述，而不是Frog本身，这样一来Frog就不能"永生"了，因为每一个egg都不等同于
// 它的母体， 而且每一次测试，大部分条件反射的建立都必须从头开始训练，类似于人类，无论人类社会有多聪明， 婴儿始终是一张白纸，需要花大量的时间从头学习。
type Egg struct {
	BrainRadius float64
	CellGroups  []*CellGroup
}

const CELL_GROUP_QTY int = 30

func CreateBrandNewEgg() *Egg {
	// 初始化随机数生成器
	// rand.Seed(time.Now().UnixNano())

	egg := new(Egg)
	egg.BrainRadius = 1000
	egg.CellGroups = make([]*CellGroup, CELL_GROUP_QTY)

	for i := 0; i < CELL_GROUP_QTY; i++ {
		var cellGroup CellGroup

		// 随机初始化GroupInputZone
		inputX := rand.Float64() * egg.BrainRadius
		inputY := rand.Float64() * egg.BrainRadius
		inputRadius := rand.Float64() * egg.BrainRadius * 0.01
		cellGroup.GroupInputZone = Zone{X: inputX, Y: inputY, Radius: inputRadius}

		// 随机初始化GroupOutputZone
		outputX := rand.Float64() * egg.BrainRadius
		outputY := rand.Float64() * egg.BrainRadius
		outputRadius := rand.Float64() * egg.BrainRadius * 0.01
		cellGroup.GroupOutputZone = Zone{X: outputX, Y: outputY, Radius: outputRadius}

		// 随机初始化其他属性
		cellGroup.CellQty = rand.Intn(10)
		cellGroup.CellInputRadius = rand.Float64() * 0.001
		cellGroup.CellOutputRadius = rand.Float64() * 0.001
		cellGroup.InputQtyPerCell = rand.Intn(10)
		cellGroup.OutputQtyPerCell = rand.Intn(5)

		egg.CellGroups[i] = &cellGroup
	}

	return egg
}
